﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using System.Windows.Input;
using Peter.Common.Interfaces;

namespace Peter.Common
{
   /// <summary>
   /// A base class for a tool window in peter.
   /// </summary>
   public abstract class PeterToolWindow : PeterDockItem, IPeterToolWindow
   {
      private bool m_IsVisible;
      private RelayCommand m_CmdHide;
      private RelayCommand m_CmdClose;
      
      /// <summary>
      /// Gets or Sets if the tool window is visible or not.
      /// </summary>
      public bool IsVisible
      {
         get { return this.m_IsVisible; }
         set
         {
            this.m_IsVisible = value;
            this.RaisePropertyChanged ("IsVisible");
         }
      }

      /// <summary>
      /// Gets the command to close the tool window.
      /// </summary>
      public ICommand CloseCommand
      {
         get { return this.m_CmdClose ?? (this.m_CmdClose = new RelayCommand (this.OnClose, this.CanClose)); }
      }

      /// <summary>
      /// Checks to see if the dock item can be closed or not.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      /// <returns>True if dock item can be closed, otherwise false.</returns>
      protected virtual bool CanClose (object obj)
      {
         return true;
      }

      /// <summary>
      /// Closes the dock item.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      protected virtual void OnClose (object obj)
      {
         this.Peter.CloseToolWindow (this);
      }

      /// <summary>
      /// Gets the command to hide the tool window.
      /// </summary>
      public ICommand HideCommand
      {
         get { return this.m_CmdHide ?? (this.m_CmdHide = new RelayCommand (this.OnHide, this.CanHide)); }
      }

      /// <summary>
      /// Checks to see if the dock item can be hidden or not.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      /// <returns>True if dock item can be hidden, otherwise false.</returns>
      protected virtual bool CanHide (object obj)
      {
         return true;
      }

      /// <summary>
      /// Hides the dock item.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      protected virtual void OnHide (object obj)
      {
         this.IsVisible = false;
         this.Peter.CloseToolWindow (this);
      }
   }
}
